package p_103

import IDoSome
import java.net.URL
import java.net.URLConnection

class HeaderViewer : IDoSome {

    val resourcePath = "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2737875068,3682183777&fm=26&gp=0.jpg"

    override fun doSome() {
        val url = URL(resourcePath)
        val uc = url.openConnection()
//        println("Content-Type:${uc.contentType}")
//        println("Content-Encoding:${uc.contentEncoding}")
//        println("Date:${Date(uc.expiration)}")
//        println("Last-Modified:${Date(uc.expiration)}")
//        println("Expiration date :${Date(uc.expiration)}")
//        println("Content-length :${uc.contentLength}")

        printAllHeaders(uc)
    }

    private fun printAllHeaders(uc: URLConnection) {
        for (item in uc.headerFields) {
            val values = item.value
            for (itemSecond in values) {
                val key = item.key ?: ""
                println("$key:$itemSecond")
            }
        }

    }

}